<template>
  <div class="container">
    <h3>{{ title }}</h3>
    <el-form ref="loginForm" :model="model" :rules="rules">
      <el-form-item prop="userName">
        <span class="svg-container svg-container_login">
          <svg-icon icon-class="user" />
        </span>
        <el-input
          v-model="model.userName"
          placeholder="请输入用户名"
        ></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <span class="svg-container">
          <svg-icon icon-class="password"></svg-icon>
        </span>
        <el-input
          :type="pwdType"
          v-model="model.password"
          placeholder="请输入密码"
        ></el-input>
        <span class="show-pwd" @click="showPwd">
          <svg-icon :icon-class="eyeIcon" />
        </span>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          style="width: 100%; letter-spacing: 10px"
          :loading="loading"
          @click.native.prevent="handleLogin"
          >登 录</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { formValidateGen } from '@/utils/form-validator-gen'
export default {
  name: 'Login',
  data () {
    return {
      model: {
        userName: '',
        password: ''
      },
      title: '登录',
      pwdType: 'password',
      loading: false,
      eyeIcon: 'eye_close',
      rules: {
        userName: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { validator: formValidateGen('validateName', '不合法的用户名'), trigger: 'change' }],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { validator: formValidateGen('validatePass', '长度不超过6位的合法字符'), trigger: 'change' }]
      }
    }
  },
  methods: {
    showPwd () {
      if (this.pwdType === 'password') {
        this.pwdType = ''
        this.eyeIcon = 'eye_open'
      } else {
        this.pwdType = 'password'
        this.eyeIcon = 'eye_close'
      }
    },
    handleLogin () {
      console.log('login')
    }
  }

}
</script>

<style lang="scss" scoped>
$bg: #2d3a4b;
$light_gray: rgb(12, 12, 12);

.container {
  width: 50%;
  margin: 0 auto;
  .el-form-item {
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 5px;
    color: #454545;
  }
  ::v-deep .el-input {
    display: inline-block;
    width: 85%;
    input {
      background: transparent;
      border: 0px;
      -webkit-appearance: none;
      border-radius: 0px;
      color: $light_gray;
      padding: 12px 5px 15px 15px;
      &:-webkit-autofill {
        box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-box-shadow: 0 0 0px 1000px $bg inset !important;
        -webkit-text-fill-color: #fff !important;
      }
    }
  }
  .svg-container {
    padding: 6px 5px 6px 15px;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
    &_login {
      font-size: 20px;
      padding: 6px 5px 6px 12px;
    }
  }
  .show-pwd {
    position: absolute;
    right: 10px;
    top: 7px;
    font-size: 16px;
    cursor: pointer;
    user-select: none;
  }
}
</style>
